import 'package:flutter/material.dart';

class ColorConvert {
  // 颜色名称到Flutter颜色的映射
  static const Map<String, Color> colorMap = {
    'red': Colors.red,
    'blue': Colors.blue,
    'green': Colors.green,
    'yellow': Colors.yellow,
    'orange': Colors.orange,
    'purple': Colors.purple,
    'teal': Colors.teal,
    'pink': Colors.pink,
    'indigo': Colors.indigo,
    'amber': Colors.amber,
    'cyan': Colors.cyan,
    'lime': Colors.lime,
    'brown': Colors.brown,
    'deepOrange': Colors.deepOrange,
    'lightBlue': Colors.lightBlue,
    'grey': Colors.grey,
    'black': Colors.black,
    'white': Colors.white,
  };

  static Color getColorFromName(String colorName) {
    // 统一转换为小写以忽略大小写差异
    final lowerCaseName = colorName.toLowerCase();

    // 尝试在映射中查找颜色
    if (colorMap.containsKey(lowerCaseName)) {
      return colorMap[lowerCaseName]!;
    }

    // 尝试匹配部分名称
    for (var key in colorMap.keys) {
      if (lowerCaseName.contains(key)) {
        return colorMap[key]!;
      }
    }

    // 默认返回灰色
    return Colors.grey;
  }
}
